app.controller("specificationController",function ($controller,$scope,specificationService) {
    //伪继承
    $controller("baseController",{$scope:$scope});
    //定义规格及规格选项
    $scope.specification={"spec":{},"options":[]};

    //查询所有的规格列表
    $scope.findAll=()=>{
        specificationService.findAll().success(resp=>{
            $scope.list = resp;
        })
    }

    //保存规格
    $scope.save=()=>{
        let url = "../specification/add.do";    //添加
        if($scope.specification.spec.id){                   //如果有id存在，就是修改操作
            url = "../specification/update.do"; //修改
        }
        //提交修改
        specificationService.save(url,$scope.specification).success(resp=>{
            if(resp.success){
                $scope.findAll();    //刷新页面
            }else{
                alert(resp.message);
            }
        })
    }

    //根据id查询规格及规格选项
    $scope.findOne=(specId)=>{
        specificationService.findOne(specId).success(resp=>{
            $scope.specification = resp;
        })
    }

    //删除规格
    $scope.del=()=>{
        specificationService.del($scope.selectIds).success(resp=>{
            if(resp.success){
                $scope.findAll();    //刷新页面
            }else{
                alert(resp.message);
            }
        })
    }
})